package com.nuts.base.bean;

import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;


/**
 * 树结构VO
 * 
 * @author 许自辉
 * @date 2017年8月14日
 */
@Getter 
@Setter 
@ToString
public class MenuTreeVO extends BaseTreeVO {

	private String icon;
	
	private String name;
	
	private String path;
	
	private String redirect;
	
	private String remark;
	
	private String permissionCode;
	
	private Integer permissionFlag;
	private String permissionFlagName;
	private Integer orderNum;
	
	private List<MenuTreeVO> children;

	/**
	 * list生成树结构
	 */
	public static List<MenuTreeVO> getTreeList(List<MenuTreeVO> treeVOs) {
		List<MenuTreeVO> rootTrees = new ArrayList<MenuTreeVO>();
		for (MenuTreeVO tree : treeVOs) {
			if (tree.getParentId() == 0) {
				rootTrees.add(tree);
			}
			for (MenuTreeVO t : treeVOs) {
				if (t.getParentId() == tree.getId()) {
					if (tree.getChildren() == null) {
						List<MenuTreeVO> myChildrens = new ArrayList<MenuTreeVO>();
						myChildrens.add(t);
						tree.setChildren(myChildrens);
					} else {
						tree.getChildren().add(t);
					}
				}
			}
		}
		return rootTrees;
	}
	
	
}
